<template>
	<el-container>
		<el-header style="height: auto;">
			<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
		</el-header>
		<el-header>
			<div class="left-panel">
				<el-button type="primary" icon="el-icon-plus" @click="uploadData">上报</el-button>
			</div>
			<div class="right-panel">
				<el-form-item label="上报人" style="padding-top: 20px;" label-width="80px">
					<select-user-dialog v-model:accountId="search.fromAccountId" :mode="false"/>
				</el-form-item>
				<el-form-item label="上报部门" style="padding-top: 20px;" label-width="80px">
					<select-dept-dialog v-model:deptId="search.deptId" :mode="false"/>
				</el-form-item>
				<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="标题 / 摘要"></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="recordId" @selection-change="selectionChange" stripe remoteSort remoteFilter>
				<el-table-column type="selection" width="50"></el-table-column>
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column label="信息标题" prop="title" width="300" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="信息类型" prop="dataTypeName" width="100"></el-table-column>
				<el-table-column label="上报部门" prop="deptName" width="150"></el-table-column>
				<el-table-column label="上报人" prop="fromUserName" width="100"></el-table-column>
				<el-table-column label="处理方式" prop="approvedTypeName" width="100"></el-table-column>
				<el-table-column label="处理状态" prop="approvedTypeName" width="100">
					<template #default="scope">
						<el-button type="primary" size="small" v-if="scope.row.status==='0'">处理中</el-button>
						<el-button type="danger" size="small" v-else-if="scope.row.status==='1'">已处理</el-button>
						<el-button type="info" size="small" v-else>未知</el-button>
					</template>
				</el-table-column>
				<el-table-column label="信息摘要" prop="subheading" width="400" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="210">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
							<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
							<el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
								<template #reference>
									<el-button text type="primary" size="small">删除</el-button>
								</template>
							</el-popconfirm>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></save-dialog>
	<data-details v-if="dialog.detailsSave" ref="detailsDialog" @closed="dialog.detailsSave=false"></data-details>
</template>

<script>
import scSelectFilter from '@/components/scSelectFilter'
import saveDialog from './save'
import selectUserDialog from "@/views/module/selectUserDialog";
import selectDeptDialog from "@/views/module/selectDeptDialog";
import dataDetails from "@/views/info/updata/details";

export default {
	name: 'Upload Data',
	components: {
		dataDetails,
		saveDialog,
		scSelectFilter,
		selectUserDialog,
		selectDeptDialog
	},
	data() {
		return {
			dialog: {
				save: false,
				detailsSave: false
			},
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "信息类型",
					key: "dataType",
					multiple: false,
					options: [{
						label: "全部",
						value: ""
					}]
				},
				{
					title: "处理方式",
					key: "approvedType",
					multiple: false,
					options: [{
						value: '',
						label: '全部'
					}],
				}
			],
			apiObj: this.$API.info.uploadData.getDataUploadInfoList,
			selection: [],
			search: {
				approvedType: '',
				dataType: '',
				date: '',
				fromAccountId: '',
				deptId: '',
				keyword: null
			}
		}
	},
	mounted() {
		this.getSysDicByCode();
	},
	methods: {
		async getSysDicByCode() {
			var res = await this.$API.system.sysDic.getSysDicByCode.get({code: 'updata'});
			if (res.code == 200) {
				this.filterData[1].options = this.filterData[1].options.concat(res.data);
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
			res = await this.$API.system.sysDic.getSysDicByCode.get({code: 'approvedType'});
			if (res.code == 200) {
				this.filterData[2].options = this.filterData[2].options.concat(res.data);
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//添加
		uploadData() {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open()
			})
		},
		//编辑
		table_edit(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(row)
			})
		},
		//查看
		table_show(row) {
			this.dialog.detailsSave = true
			this.$nextTick(() => {
				this.$refs.detailsDialog.open().setData(row)
			})
		},
		//删除
		async table_del(row) {
			var reqData = {recordId: row.recordId}
			var res = await this.$API.info.uploadData.deleteDataUploadInfo.post(reqData);
			if (res.code == 200) {
				this.$refs.table.refresh()
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//表格选择后回调事件
		selectionChange(selection) {
			this.selection = selection;
		},
		//搜索
		async upsearch() {
			this.$refs.table.upData(this.search)
		},
		filterChange(data) {
			this.search.approvedType = data.approvedType;
			this.search.date = data.date;
			this.search.dataType = data.dataType
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSaveSuccess() {
			this.$refs.table.refresh()
		},
	}
}
</script>

<style>
</style>
